package com.packet.cheng;

import redis.clients.jedis.*;

import java.util.HashSet;
import java.util.Set;

/**
 @author zaicheng
 @version 1.0
 @date 2022-04-19
 @email zzc15847256473@163.com
 */

public class JedisSentinelTest {

    public static void main(String[] args) {

        JedisPoolConfig jedisPoolConfig  = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(20);
        jedisPoolConfig.setMaxIdle(10);
        jedisPoolConfig.setMinIdle(5);

        String masterName = "mymaster";
        Set<String> sentinels = new HashSet<>();
        sentinels.add(new HostAndPort("192.168.43.66",26379).toString());
        sentinels.add(new HostAndPort("192.168.43.66",26380).toString());
        sentinels.add(new HostAndPort("192.168.43.66",26381).toString());

        JedisSentinelPool jedisSentinelPool  = new JedisSentinelPool(masterName,sentinels,jedisPoolConfig,3000,null);

        Jedis jedis = null;

        try {

            jedis = jedisSentinelPool.getResource();

            System.out.println(jedis.set("sentinel","zaicheng"));

            System.out.println(jedis.get("sentinel"));

        }catch (Exception  e){

        }finally {
            if (jedis != null){
                jedis.close();
            }
        }
    }
}
